package com.example.net.retrofit;

import android.util.Log;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * create by Test on 2024/4/11 Time：17:01
 * describe:
 */
public class RetrofitImpl {
    private static RetrofitImpl sInstance = new RetrofitImpl();
    private Retrofit mRetrofit;
    public static Retrofit getRetrofit(){
        return sInstance.mRetrofit;
    }

    private RetrofitImpl(){
        HttpLoggingInterceptor logging = new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() {
            @Override
            public void log(String message) {
                Log.d("mjt",message);
            }
        });
        logging.setLevel(HttpLoggingInterceptor.Level.BODY);
        OkHttpClient okHttpClient = new OkHttpClient().newBuilder()
               // .connectTimeout()
                .addInterceptor(logging)
                .build();
        mRetrofit =  new Retrofit.Builder()
              .client(okHttpClient)
              // getUrl是：http://www.imooc.com/api/okhttp/getmethod
              // postUrl :http://www.imooc.com/api/okhttp/postmethod
              //baseUrl是都有前缀： http://www.imooc.com/api/okhttp/
                .addConverterFactory(GsonConverterFactory.create())
              .baseUrl("http://www.imooc.com/api/okhttp/")
              .build();
    }
}
